<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.xea.service.ProductService"%>
<%@page import="com.xea.service.ServiceFactory"%>
<%@page import="com.xea.util.StringUtil"%>
<%@page import="com.uf.util.PageData"%>
<%@page import="com.xea.model.Product"%>
<%@include file="../../inner/head.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<link type="text/css" rel="stylesheet" href="${basepath}/res/images/style.css" />
<style>
	.miao{
		width: 234px;
		height: 248px;
		line-height:248px;
		border:1px solid #ccc;
		overflow:hidden;
		position:relative;
		text-align:center;
		margin:auto;		
	}
	.miao p {
		position:static;
		+position:absolute;
		top:50%;
	}
	
	.miao p img{
		position:static;
		+position:relative;
		top:-50%;left:-50%;
		vertical-align:middle;
		border:1px solid #353535;
	}
	.miao p:after {
		content:".";font-size:1px;
		visibility:hidden
	}
	
</style>
<body>
	<div id="list_r">
		<div style="border: #cbc9ca 1px solid;margin-right: 5px;">
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<%
				ProductService productDao = ServiceFactory.getProductService();
				String pageNo=request.getParameter("p");
				String name=request.getParameter("proname");
				String channelId=request.getParameter("channelId");
				if(StringUtil.isNullOrEmpty(pageNo) || "0".equals(pageNo))
					pageNo="1";
				if(StringUtil.isNullOrEmpty(name))
					name="";
				PageData pagedata=null;
				if(!StringUtil.isNullOrEmpty(request.getParameter("type"))){
					if(request.getParameter("type").equals("search"))
						channelId=productDao.searchout(request.getParameter("name"));
				}
				if(StringUtil.isNullOrEmpty(channelId))
					pagedata =productDao.searchout(name,pageNo); 
				if(!StringUtil.isNullOrEmpty(channelId))
					pagedata =productDao.searchout(name,Integer.valueOf(channelId), pageNo);
				List nlist = pagedata.getData();
				int cP = pagedata.getCurrentPage();
				int tP = pagedata.getTotalPage();
				int pre = cP-1<1?1:cP-1; 
				int next = cP+1>tP?tP:cP+1;
				int i=0;
				for(i=0;i<nlist.size();i++){
					Product product= (Product)nlist.get(i);
					if(product.getDescribes().length() >=140)
							product.setDescribes(product.getDescribes().substring(0,140)+"...");
			%>
			<%if(i%3==0) %><tr>
			<td>
				<div class="product">
					<div class="miao"><p><img src="<%=product.getCoverPath() %>" onclick="window.location.href='${basepath }/outer/detail.jsp?id=<%=product.getId() %>'" style="cursor: pointer;" title="<%=product.getName() %>"/></p></div>
					<div class="name">
						<div class="f_l"><%=product.getName() %></div>
						<div class="f_r"><a href="${basepath }/outer/detail.jsp?id=<%=product.getId() %>" title="<%=product.getName() %>"><img src="${basepath}/res/images/fulldetail.jpg" /></a></div>
					</div>
					<hr style=" border:none; border-top:1px solid #d8d8d8;" />
					<div class="info">
						<p><span class="tb">Item NO.:</span><%=product.getPno() %></p>
						<%if(product.getVolume()!=""){%>
						<p><span class="tb">Product size:</span><%=product.getVolume() %></p>
						<%}  %>
						<%if (product.getMaterial()!=""){%>
						<p><span class="tb">Material:</span><%=product.getMaterial() %></p>
						<%} %>
						<%if (product.getDescribes()!=""){%>
						<p>
							<span class="tb">Description:</span><br/>
							<%=product.getDescribes() %>
						</p>
						<%} %>
					</div>
				</div>
			</td>
			<%if(i%3==2) %></tr>
			<%}if(i%3!=2) %>
				</tr>
		</table>	
		<div class="pagination" style="font-weight: normal;width: 100%;" >
  		<table width="100%" border="0" align="right" cellpadding="0" cellspacing="0">
         <tr>
         	<td align="right" style="cursor: pointer;font-weight: bold;" >
       		<%
      		if(pagedata.getTotalPage() >1){
      	 	%><%-- 
       		<a href="${basepath}/outer/product.jsp?p=1&channelId=<%=channelId!=null?channelId:"" %>&type=<%=request.getParameter("type")!=null && !request.getParameter("type").equals("search")?request.getParameter("type"):"" %>&proname=<%=name!=null?name:"" %>" style="color:#89140e;padding: 3px;"/>&lt;&lt;</a>
          	<a href="${basepath}/outer/product.jsp?p=<%=pre%>&channelId=<%=channelId!=null?channelId:""  %>&type=<%=request.getParameter("type")!=null && !request.getParameter("type").equals("search")?request.getParameter("type"):"" %>&proname=<%=name!=null?name:"" %>" title="Previous" style="color:#89140e;padding: 3px;"/>Previous</a>
       		<%
					for(i=0;i<pagedata.getTotalPage();i++){	
								          			
         		%>
         		<a id="st<%=i+1%>" href="${basepath}/outer/product.jsp?p=<%=i+1 %>&channelId=<%=channelId!=null?channelId:""  %>&type=<%=request.getParameter("type")!=null && !request.getParameter("type").equals("search")?request.getParameter("type"):"" %>&proname=<%=name!=null?name:"" %>" style="color:#89140e;padding: 3px;"><%=i+1 %></a>
         		<%}%>
       		<a href="${basepath}/outer/product.jsp?p=<%=next%>&channelId=<%=channelId!=null?channelId:""  %>&type=<%=request.getParameter("type")!=null && !request.getParameter("type").equals("search")?request.getParameter("type"):"" %>&proname=<%=name!=null?name:"" %>" title="Next" style="color:#89140e;padding: 3px;">Next</a>
           	<a href="${basepath}/outer/product.jsp?p=<%=pagedata.getTotalPage()%>&channelId=<%=channelId!=null?channelId:""  %>&type=<%=request.getParameter("type")!=null && !request.getParameter("type").equals("search")?request.getParameter("type"):"" %>&proname=<%=name!=null?name:"" %>" style="color:#89140e;padding: 3px;"/>&gt;&gt;</a>
      	  	<td width="40">&nbsp;</td>--%>
      	  	<a href="${basepath}/outer/product.jsp?p=1&channelId=<%=channelId!=null?channelId:"" %>&type=<%=request.getParameter("type")!=null && !request.getParameter("type").equals("search")?request.getParameter("type"):"" %>&proname=<%=name!=null?name:"" %>" style="color:#89140e;padding: 3px;"/>&lt;&lt;</a>
          	<a href="${basepath}/outer/product.jsp?p=<%=pre%>&channelId=<%=channelId!=null?channelId:""  %>&type=<%=request.getParameter("type")!=null && !request.getParameter("type").equals("search")?request.getParameter("type"):"" %>&proname=<%=name!=null?name:"" %>" title="Previous" style="color:#89140e;padding: 3px;"/>Previous</a>
       		<font style="font-weight:bold;font-size: 16px;"><%=pagedata.getCurrentPage()%>/<%=pagedata.getTotalPage()%></font>
       		<a href="${basepath}/outer/product.jsp?p=<%=next%>&channelId=<%=channelId!=null?channelId:""  %>&type=<%=request.getParameter("type")!=null && !request.getParameter("type").equals("search")?request.getParameter("type"):"" %>&proname=<%=name!=null?name:"" %>" title="Next" style="color:#89140e;padding: 3px;">Next</a>
           	<a href="${basepath}/outer/product.jsp?p=<%=pagedata.getTotalPage()%>&channelId=<%=channelId!=null?channelId:""  %>&type=<%=request.getParameter("type")!=null && !request.getParameter("type").equals("search")?request.getParameter("type"):"" %>&proname=<%=name!=null?name:"" %>" style="color:#89140e;padding: 3px;"/>&gt;&gt;</a>
      	  	<td width="40">&nbsp;</td>
      	  	<%} %>
      	  	</td>
      	  	<%--
      	  	<script>
      	  		if(<%=pagedata.getTotalPage()%>>1){
				$("#st"+<%=pagedata.getCurrentPage()%>).css("font-weight", "bold"); 
				$("#st"+<%=pagedata.getCurrentPage()%>).css("font-size", "16px"); 
			}
      	  	</script>
      	  	--%>
      	  </tr>
      	  <input id="pageNo" name="pageNo" type="hidden" value="<%=pagedata.getCurrentPage() %>"/>
 		</table>
		  		&nbsp;
		
		</div>	
	</div>
	</div>
</form>
</body>
